<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" v-show="showSearch" label-width="68px" class="form-flex">
        <el-row :gutter="20">
            <el-col :span="6" :xs="24">
                    <el-form-item label="合同类型ID" prop="contractCategoryId">
                    <el-input
                            v-model="queryParams.contractCategoryId"
                            placeholder="请输入合同类型ID"
                            clearable
                            size="small"
                            @keyup.enter.native="handleQuery"
                    />
                </el-form-item>
            </el-col>
            <el-col :span="6" :xs="24">
                    <el-form-item label="甲方名称" prop="partyName">
                    <el-input
                            v-model="queryParams.partyName"
                            placeholder="请输入甲方名称"
                            clearable
                            size="small"
                            @keyup.enter.native="handleQuery"
                    />
                </el-form-item>
            </el-col>
            <el-col :span="6" :xs="24">
                    <el-form-item label="甲方手机号" prop="partyPhone">
                    <el-input
                            v-model="queryParams.partyPhone"
                            placeholder="请输入甲方手机号"
                            clearable
                            size="small"
                            @keyup.enter.native="handleQuery"
                    />
                </el-form-item>
            </el-col>
            <el-col :span="6" :xs="24">
                    <el-form-item label="联系人" prop="partyContacts">
                    <el-input
                            v-model="queryParams.partyContacts"
                            placeholder="请输入联系人"
                            clearable
                            size="small"
                            @keyup.enter.native="handleQuery"
                    />
                </el-form-item>
            </el-col>
            <el-col :span="6" :xs="24">
                <el-form-item>
                    <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
                    <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
                </el-form-item>
            </el-col>
        </el-row>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd" v-hasPermi="['lease:firstParty:add']">新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="success" plain icon="el-icon-edit" size="mini" :disabled="single" @click="handleUpdate" v-hasPermi="['lease:firstParty:edit']">修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="danger" plain icon="el-icon-delete" size="mini" :disabled="multiple" @click="handleDelete" v-hasPermi="['lease:firstParty:remove']">删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="warning" plain icon="el-icon-download" size="mini" :loading="exportLoading" @click="handleExport" v-hasPermi="['lease:firstParty:export']">导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="firstPartyList" @selection-change="handleSelectionChange">
        <el-table-column type="selection" width="55" align="center" />
            <el-table-column label="id主键" align="center" prop="id" />
                <el-table-column label="合同类型ID" align="center" prop="contractCategoryId" />
            <el-table-column label="甲方名称" align="center" prop="partyName" />
            <el-table-column label="甲方手机号" align="center" prop="partyPhone" />
            <el-table-column label="联系人" align="center" prop="partyContacts" />
                            <el-table-column label="备注" align="center" prop="remark" />
          <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
            <template slot-scope="scope">
              <el-button
                size="mini"
                type="text"
                icon="el-icon-edit"
                @click="handleUpdate(scope.row)"
                v-hasPermi="['lease:firstParty:edit']"
              >修改</el-button>
              <el-button
                size="mini"
                type="text"
                icon="el-icon-delete"
                @click="handleDelete(scope.row)"
                v-hasPermi="['lease:firstParty:remove']"
              >删除</el-button>
            </template>
          </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

      <FirstPartyForm ref="formRef" @cancel="getList" />
  </div>
</template>

<script>

import { listMixin } from "@/utils/mixins/listMixin";
import { listFirstParty, delFirstParty, exportFirstParty } from "@/api/lease/firstParty";
import FirstPartyForm from "./form.vue"

export default {
  name: "FirstParty",
  components:{ FirstPartyForm },
  mixins:[ listMixin ],
  data() {
    return {
      // 甲方信息管理表格数据
      firstPartyList: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        contractCategoryId: null,
        partyName: null,
        partyPhone: null,
        partyContacts: null,
      },
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询甲方信息管理列表 */
    getList() {
      this.loading = true;
      listFirstParty(this.queryParams).then(response => {
        this.firstPartyList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.$refs.formRef.show({"type":"ADD"});
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      const id = row.id || this.ids
      const option = {
          "type":"UPDATE",
          "id": id
      }
      this.$refs.formRef.show(option);
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$confirm('是否确认删除甲方信息管理编号为"' + ids + '"的数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return delFirstParty(ids);
        }).then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$confirm('是否确认导出所有甲方信息管理数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(() => {
          this.exportLoading = true;
          return exportFirstParty(queryParams);
        }).then(response => {
          this.download(response.msg);
          this.exportLoading = false;
        }).catch(() => {});
    }
  }
};
</script>
